
package com.ruoyi.web.controller.pay;


import com.alipay.api.AlipayApiException;

import com.ruoyi.web.utils.PayData;
import com.ruoyi.web.utils.Result;
import com.ruoyi.web.utils.WxPayUtils;
import com.ruoyi.web.utils.ZhifubaoUtill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private WxPayUtils wxPayUtils;

    @Autowired
    private ZhifubaoUtill zhifubaoUtill;



    /**
     * 支付宝支付
     * @param
     * @return
     * @throws AlipayApiException
     * @throws
     */
    @PostMapping("/zfbpay")
    public Result zfbpay(@RequestBody PayData payData) throws IOException, AlipayApiException {
        Map map = zhifubaoUtill.pay(payData);
        String form = (String) map.get("form");

        FileOutputStream fileOutputStream = new FileOutputStream("D://html/" + payData.getCode() + ".html");
        fileOutputStream.write(form.getBytes());
        fileOutputStream.close();
        File file = new File("D://html/"+payData.getCode()+".html");
        Runtime runtime = Runtime.getRuntime();
        runtime.exec("cmd /c start "+file.getAbsolutePath());
        return Result.succeed(form.getBytes());
    }

}

